<?php

namespace App\Http\Model;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements AuthenticatableContract,
                                    AuthorizableContract,
                                    CanResetPasswordContract
{
    use Authenticatable, Authorizable, CanResetPassword;
    //此模型关联的数据表
    protected $table = 'user';

//    表的主键
    public $primaryKey = 'user_id';
    //不更新created_at  updated_at字段
    public $timestamps = false;

    //是否允许批量填充数据
//    public $fillable = ['user_name','user_pass'];


//    不允许批量填充的字段  如果设置$fillable 就不要在设置$guarded
    public $guarded = [];

    public function roles()
    {
//        参数一 要关联的模型
//        参数二  将两个模型联系起来的关联表的表名
//        参数三 当前模型在关联表中的字段名
//        参数四 被关联模型在关联表中的字段名
//        return $this->belongsToMany('App\Role', 'user_roles', 'user_id', 'role_id');


        return $this->belongsToMany('App\Http\Model\Role','role_user','user_id','role_id');
    }
}
